package com.holly.unit.bpmn.modular.activiti.controller;


import com.fasterxml.jackson.databind.node.ObjectNode;
import com.holly.unit.bpmn.activiti.ActivitiOperator;
import com.holly.unit.scanner.api.annotation.ApiResource;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 类描述: 集成Diagram Viewer
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/2/8 14:45
 */
@Controller
@ApiResource(name = "流程追踪插件")
@Api(tags = "流程追踪插件API")
@RequestMapping("activiti/activitiService")
public class DiagramViewerController {

    @Resource
    private ActivitiOperator operator;

    @RequestMapping(value = "/diaurl",method = {RequestMethod.GET})
    public String url() {
        return "index";
    }


    @ResponseBody
    @RequestMapping(
            value = {"/process-instance/{processInstanceId}/highlights"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    public ObjectNode getHighlighted(@PathVariable String processInstanceId) {
        return operator.getHighlighted(processInstanceId);
    }

    @RequestMapping(
            value = {"/process-instance/{processInstanceId}/diagram-layout"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public ObjectNode getDiagramByInstanceId(@PathVariable String processInstanceId) {
        return operator.getDiagramByInstanceId(processInstanceId);
    }

    @RequestMapping(
            value = {"/process-definition/{processDefinitionId}/diagram-layout"},
            method = {RequestMethod.GET},
            produces = {"application/json"}
    )
    @ResponseBody
    public ObjectNode getDiagram(@PathVariable String processDefinitionId) {
        return operator.getDiagramByDefinitionId(processDefinitionId);
    }


}
